<template>
  <div class="login-container">
    <el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left"
             label-width="0px"
             class="card-box login-form">
      <h3 class="title">
        <img src="../../../assets/images/logo.png" alt="">
        微信公众号数据统计平台
      </h3>
      <el-form-item prop="username">
        <span class="svg-container">
           <icon-svg icon-class="account" />
        </span>
        <el-input size="small" name="username" type="text" v-model="loginForm.username" autoComplete="on"
                  placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <icon-svg icon-class="password" />
        </span>
        <el-input size="small" name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password"
                  autoComplete="on" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="success" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
          登录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex';
  import { isEmail } from '@/utils/validate';

  export default {
    data() {
      const validatePass = (rule, value, callback) => {
        if (value.length < 6) {
          callback(new Error('密码不能小于6位'));
        } else {
          callback();
        }
      };
      return {
        loginForm: {
          username: '',
          password: ''
        },
        loginRules: {
          username: [
            { required: true, trigger: 'blur', message: "请输入用户名"}
          ],
          password: [
            { required: true, trigger: 'blur', validator: validatePass }
          ]
        },
        loading: false,
        showDialog: false
      }
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.loading = true;
            this.$store.dispatch('LoginByUserName', this.loginForm).then(() => {
              this.loading = false;
              this.$router.push({ path: '/' });
              // this.showDialog = true;
            }).catch(err => {
              this.$message.error(err);
              this.loading = false;
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>

<style lang="less">
  .login-container {
    position: relative;
    width: 100%;
    height: 100vh;
    /*background-color: #eee;*/
    overflow: hidden;

    .fireworks{
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      top: 0;
    }

    input:-webkit-autofill {
      -webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
      -webkit-text-fill-color: #fff !important;
    }
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 10px;
      color: #666;
    }
    .el-input {
      display: inline-block;
      width: 85%;
    }
    .svg-container {
      padding: 6px 0 6px 15px;
      color: #889aa4;
      .icon-svg{
        margin-right: 0;
      }
    }

    .title {
      font-size: 20px;
      color: #8A8A8A;
      margin: 0px auto 30px auto;
      text-align: center;
      font-weight: bold;
      img{
        display: block;
        margin: auto;
        width: 60px;
        margin-bottom: 15px;
      }
    }

    .login-form {
      /*border-top: 3px solid #63a8f3;*/
      position: absolute;
      left: 50%;
      top: 50%;
      width: 380px;
      margin-left: -160px;
      margin-top: -280px;
      background: #fff;
      padding: 32px;
    }

    .el-form-item {
      border: 1px solid #ddd;
      border-radius: 5px;
    }

    .forget-pwd {
      color: #fff;
    }
  }

</style>
